package rpg.visual.window;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;

import pgui.PVisual;
import pgui.visual.PComponent;

public class VisualWindowBorderRight extends PComponent {

	public VisualWindowBorderRight(PVisual visual) {
		super(visual);
		
		this.setX(-3);
		this.setRelativeX(100);
		this.setWidth(3);
		
		this.setRelativeHeight(100);
	}
	
	// Mouse Events
	@Override
	public void onMouseMoved(MouseEvent event, MouseEvent lastEvent) {
		super.onMouseMoved(event, lastEvent);
		setCursor(Cursor.E_RESIZE_CURSOR);
		mouseLock(false);
	}
	
	@Override
	public void onMouseExited(MouseEvent event, MouseEvent lastEvent) {
		super.onMouseExited(event, lastEvent);
		setCursor(Cursor.DEFAULT_CURSOR);
		mouseLock(false);
	}
	
	@Override
	public void onMousePressed(MouseEvent event) {
		super.onMousePressed(event);
		mouseLock(true);
	}
	
	@Override
	public void onMouseReleased(MouseEvent event) {
		super.onMouseReleased(event);
		mouseLock(false);
		setCursor(Cursor.DEFAULT_CURSOR);
	}
	
	@Override
	public void onMouseDragged(MouseEvent event, MouseEvent lastEvent) {
		super.onMouseDragged(event, lastEvent);
		
		int resizeX = event.getX() - lastEvent.getX();
		this.getParent().setWidth(this.getParent().getWidth() + resizeX);
		
		if(this.getParent().getWidth() < VisualWindow.MINIMUM_WIDTH)
			this.getParent().setWidth(VisualWindow.MINIMUM_WIDTH);
	}
	
	// Paint Events
	@Override
	public void onPaint(Graphics2D g) {
		super.onPaint(g);
		
		g.setColor(Color.white);
		g.drawRect(3, 0, 0, this.getLastHeight());
	}
}
